package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.vo.PwsAndSapAndRgblVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Rgbl;
import com.ruoyi.system.service.IRgblService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2025-02-13
 */
@RestController
@RequestMapping("/system/rgbl")
@Api(tags = "人工备料管理")
public class RgblController extends BaseController
{
    @Autowired
    private IRgblService rgblService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:rgbl:list')")
    @GetMapping("/list")
    @ApiOperation("查询备料列表")
    public TableDataInfo list(@RequestBody Rgbl rgbl, @RequestParam Integer pageNum, @RequestParam Integer pageSize)
    {
        List<Rgbl> list = rgblService.selectRgblList(rgbl,pageNum,pageSize);
        Long total = rgblService.selectRgblCount(rgbl);
        return getDataTable(list,total);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:rgbl:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出备料列表")
    public void export(HttpServletResponse response, Rgbl rgbl)
    {
        List<Rgbl> list = rgblService.selectRgblAll(rgbl);
        ExcelUtil<Rgbl> util = new ExcelUtil<Rgbl>(Rgbl.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:rgbl:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("查询备料详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(rgblService.selectRgblById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:rgbl:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增备料")
    public AjaxResult add(@RequestBody Rgbl rgbl)
    {
        return toAjax(rgblService.insertRgbl(rgbl));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:rgbl:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    @ApiOperation("修改备料")
    public AjaxResult edit(@RequestBody Rgbl rgbl)
    {
        return toAjax(rgblService.updateRgbl(rgbl));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:rgbl:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除备料")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rgblService.deleteRgblByIds(ids));
    }

    @PostMapping("/addOrUpdateRgbl")
    @ApiOperation(value = "打印人工备料单数据保存", notes = "传入主键（id）集合")
    public AjaxResult addOrUpdateRgbl(@RequestBody List<Long> ids){
        if(ids.size()==0){
            return error("请选择数据");
        }
         boolean flag=rgblService.addOrUpdateRgbl(ids);
         if(flag){
             //return success("保存成功");
             List<PwsAndSapAndRgblVo> pwsAndSapAndRgblVos=rgblService.selectPwsAndSapAndRgblVoByIds(ids);
             return success(pwsAndSapAndRgblVos);
         }else{
             return error("保存失败");
         }

    }
}
